﻿using System;
using System.Collections.Generic;
using System.IO;

namespace SortedList
{
    class SortedList
    {
        static List<string> ReadLines(string path)
        {
            List<string> lines = new List<string>();
            string line;

            using (StreamReader reader = new StreamReader(path))
            {
                while ((line = reader.ReadLine()) != null)
                {
                    lines.Add(line);
                }
            }

            return lines;
        }

        static void WriteLines(List<string> sortedList, string path)
        {
            using (StreamWriter writer = new StreamWriter(path))
            {
                foreach (string item in sortedList)
                {
                    writer.WriteLine(item);
                }
            }
        }

        static void Main()
        {
            string unsortedFile = "..\\..\\UnsortedList.txt";
            string sortedFile = "..\\..\\SortedList.txt";
            List<string> lines = ReadLines(unsortedFile);

            lines.Sort();

            WriteLines(lines, sortedFile);
        }
    }
}
